package com.info.examples.strategy;

import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 打折促销
 */
@Service
public class DiscountPromoteServiceImpl implements PromoteSalesService {

    // 满100打9折，199以上打85折
    @Override
    public BigDecimal getPromotionPrice(BigDecimal originalPrice) {
        if (new BigDecimal("100").compareTo(originalPrice) > 0) {
            return originalPrice;
        } else if (new BigDecimal("199").compareTo(originalPrice) >= 0) {
            return originalPrice.multiply(new BigDecimal("0.9"));
        }
        return originalPrice.multiply(new BigDecimal("0.85"));
    }

    @Override
    public PromoteTypeEnum getType() {
        return PromoteTypeEnum.DISCOUNT;
    }
}
